const localStorage = window.localStorage
const optimizedLocalStorage = {
  length: {
    get () {
      return localStorage.length
    },
    set (length) {
      localStorage.length = length
    }
  },
  key (index) {
    return localStorage.key(index)
  },
  getItem (key) {
    const serializedValue = localStorage.getItem(key)
    return serializedValue ? JSON.parse(serializedValue) : void 0
  },
  setItem (key, value) {
    localStorage.setItem(key, JSON.stringify(value))
  },
  removeItem (key) {
    localStorage.removeItem(key)
  },
  clear () {
    localStorage.clear()
  }
}
export default optimizedLocalStorage
